//
//  RW_UserSingleViewModel.m
//  SleepApp
//
//  Created by chuangqi on 2021/4/7.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_UserSingleListViewModel.h"
#import "RW_UserSingleListItemCell.h"
#import "RW_UserSingleListItemCell.h"

@implementation RW_UserSingleListViewModel



#pragma mark -- 视图模型获取
/** 获取视图模型 */
-(void)getViewSuccess:(void(^)(NSArray<WLBaseCollectionViewLayerSection *> *response))success
                 fail:(void(^)(NSError *error))fail{
    [[[RW_UserSingleModel getUserSingleSongListId:self.wlclass_user_songle_model.xid] then:^id _Nullable(RW_UserSingleModel * _Nullable value) {
        if (success){
            success([self getUserSingleSongSection:value.list]);
        }
        return nil;
    }] catch:fail];
}

#pragma mark -- 视图模型生成
/** 生成收藏歌单列表视图 */
-(NSArray<WLBaseCollectionViewLayerSection *> *)getUserSingleSongSection:(NSArray<RW_UserSongModel *> *)singleList{
    NSMutableArray *array = [NSMutableArray array];
    
    WLBaseCollectionViewLayerSection *section = [[WLBaseCollectionViewLayerSection alloc]init];
    section.horizontalMaxWidth = Main_Screen_Width;
    
    CGSize itemSize = CGSizeZero;
    
        section.insetForSection = UIEdgeInsetsMake(1, 0, 1, 0);
        section.horizontalSection = 0;
        section.horizontalCount = 1;
        section.verticalSection = 1;
    
        itemSize = [section getCellSizeHeight:60];

    for (RW_UserSongModel *obj in singleList) {
        RW_UserSingleListItemCellModel *model = [[RW_UserSingleListItemCellModel alloc]init];
        model.user_song_model = obj;
        [section.item addObject:[RW_UserSingleListItemCell getRow:model
                                                         cellSize:itemSize]];
    }
    [array addObject:section];
    return array;
}

@end
